<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //选择排序
      //  选择一个默认值，然后进行两两对比
      var arr = [23,12,4,2,6]
      function selector(arr){
        for(var n = 0 ; n < arr.length- 1; n++){
            var minValue = arr[n]
        var minIndex = n
    for(var i = n+1 ; i <arr.length ; i++){
        if(minValue > arr[i]){
            minValue = arr[i]
            minIndex = i
        }
        }
        arr[minIndex] = arr[n];
      arr[n] = minValue;
    }
    return arr
      }
    console.log(selector(arr))  
    </script>
</body>
</html>